<template>

  <!--
          作者：luoyiming
          时间：2019-10-25
          描述：门店列表
      -->
  <div class="user">
    <!--添加门店-->
    <!-- <div class="common-level-rail"><el-button size="small" type="primary" icon="Plus" @click="addClick" v-auth="'/store/store/add'">添加门店</el-button></div> -->

    <!--内容-->
    <div class="product-content">
      <div class="table-wrap">
        <el-table size="small" :data="tableData" border style="width: 100%" v-loading="loading">
          <el-table-column prop="userId" label="用戶ID" width="160"></el-table-column>
          <el-table-column label="發送人暱稱">
            <template #default="scope">
              <div v-if="scope.row.sendType==1">
                <span>{{scope.row.supplierUserName}}</span>
              </div>
              <div v-else><span>{{scope.row.nickName}}</span></div>
            </template>
          </el-table-column>
          <el-table-column label="發送人頭像" width="100">
            <template #default="scope">
              <div v-if="scope.row.sendType==1">
                <img v-img-url="scope.row.supplierLogoh" :width="30" :height="30" />
              </div>
              <div v-else><img v-img-url="scope.row.avatarUrl" :width="30" :height="30" /></div>

            </template>
          </el-table-column>
          <el-table-column prop="content" label="發送消息">
            <template #default="scope">
              <div v-if="scope.row.msgType==0">
                <span>{{scope.row.content}}</span>
              </div>
              <div v-if="scope.row.msgType==1">
                <img v-img-url="scope.row.content" :width="100" :height="100" />
              </div>
              <div v-if="scope.row.msgType==2">
                <img v-img-url="scope.row.content.productImg" :width="50" :height="50" />
                <div class="pro_txtname nmaxwidth">{{scope.row.content.productName}}</div>
                <div class="pro_price">￥{{scope.row.content.productPrice}}</div>
              </div>
              <div class="d-s-c" v-if="scope.row.msgType==3">
                <div>
                  <img v-img-url="scope.row.content.productImg" :width="50" :height="50" />
                </div>
                <div>
                  <div class="pro_txtname nmaxwidth">訂單號：{{scope.row.content.orderNo}}</div>
                  <div class="pro_txtname nmaxwidth">商品名稱:{{scope.row.content.productName}}</div>
                  <div class="pro_price">訂單價格:￥{{scope.row.content.orderPrice}}</div>
                  <div class="pro_price">商品數量：{{scope.row.content.orderNum}}</div>
                  <div class="pro_txtname nmaxwidth">下單時間：{{scope.row.content.createTime}}</div>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="createTime" label="發送時間" width="140"></el-table-column>
        </el-table>
      </div>

      <!--分页-->
      <div class="pagination">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" background :current-page="curPage"
          :page-size="pageSize" layout="total, prev, pager, next, jumper" :total="totalDataNumber"></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import ServiceApi from '@/api/service.js';
export default {
  components: {},
  inject: ['reload'],
  data() {
    return {
      /*是否加载完成*/
      loading: true,
      /*列表数据*/
      tableData: [],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*横向表单数据模型*/
      formInline: {
        user: '',
        region: ''
      },
      /*是否打开添加弹窗*/
      open_add: false,
      /*是否打开编辑弹窗*/
      open_edit: false,
      /*当前编辑的对象*/
      userModel: {},
      userId: 0
    };
  },
  created() {
    this.userId = this.$route.query.userId;
    /*获取列表*/
    this.getTableList();
  },
  methods: {
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.curPage = val;
      self.loading = true;
      self.getTableList();
    },
    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getTableList();
    },
    /*获取列表*/
    getTableList() {
      let self = this;
      let Params = {};
      Params.userId = self.userId;
      Params.pageIndex = self.curPage;
      Params.pageSize = self.pageSize;
      ServiceApi.recordlist(Params, true).then(res => {
        self.loading = false;
        for (let i = 0; i < res.data.records.length; i++) {
          if (res.data.records[i].contentJson) {
            res.data.records[i].content = res.data.records[i].contentJson;
          }
        }
        self.tableData = res.data.records;
        self.totalDataNumber = res.data.total;
      }).catch(error => {});
    },
    /*打开添加*/
    addClick() {
      this.$router.push('/store/store/add');
    },
    /*打开编辑*/
    editClick(row) {
      let self = this;
      let params = row.store_id;
      this.$router.push({
        path: '/store/store/edit',
        // name: 'mallList',
        query: {
          store_id: params
        }
      });
    },
    /*删除*/
    deleteClick(row) {
      let self = this;
      ElMessageBox.confirm("此操作將永久刪除該記錄, 是否繼續?", "提示", {
        confirmButtonText: "確定",
        cancelButtonText: "取消",
        type: 'warning'
      }).then(() => {
        ServiceApi.deleteShop({
          store_id: row.store_id
        }, true).then(data => {
          ElMessage({
            message: "恭喜你，門店刪除成功",
            type: 'success'
          });
          self.getTableList();
        }).catch(error => {});
      }).catch(() => {});
    }
  }
};
</script>

<style>
.nmaxwidth{
    max-width: 250px;
  }
</style>

